package com.ruoyi.business.appuser.service.impl;

import com.ruoyi.business.appuser.service.RobotService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.service.MqttServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RobotServiceImpl implements RobotService {

    @Autowired
    private MqttServer mqttServer;

    @Override
    public AjaxResult forward() {
        String topic = "robot";
        String data = "forward";
        try {
            mqttServer.sendMessage(topic,data,2);
            return AjaxResult.success();
        }catch (Exception e) {
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult backward() {
        String topic = "robot";
        String data = "backward";
        try {
            mqttServer.sendMessage(topic,data,2);
            return AjaxResult.success();
        }catch (Exception e) {
            return AjaxResult.error();
        }

    }

    @Override
    public AjaxResult leftward() {
        String topic = "robot";
        String data = "leftward";
        try {
            mqttServer.sendMessage(topic,data,2);
            return AjaxResult.success();
        }catch (Exception e) {
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult rightward() {
        String topic = "robot";
        String data = "rightward";
        try {
            mqttServer.sendMessage(topic,data,2);
            return AjaxResult.success();
        }catch (Exception e) {
            return AjaxResult.error();
        }
    }
}
